<template>
	<div></div>
	<!-- <MainUIComp></MainUIComp> -->
</template>

<script>
	// import MainUIComp from './MainUIComp'

	export default {
		name: 'index',
		// components: { MainUIComp },
		data() {
			return {
				xbsjEarthUI: undefined
			}
		},
		methods: {
			initEarthWithTilesetUrl(earth, tilesetUrl, tilesetTitle) {
				var earthJsonObject = {
					"sceneTree": {
						"root": {
							"expand": true,
							"title": "预览场景",
							"children": [{
								"expand": true,
								"title": "三维瓦片组",
								"children": [{
									"czmObject": {
										"xbsjType": "XbsjTileset",
										// "guid": "c681a2cc-7f08-45a4-a8d3-2a03859b2c35",
										"url": tilesetUrl
									},
									"enabled": true,
									"title": tilesetTitle
								}],
							}]
						}
					}
				};
				earth.fromJson(earthJsonObject);
			}
		},
		mounted() {
			this.$root.$XbsjEarthUI.create('app').then((earthUI) => {
				window.uia = earthUI;

				//如果有url参数，那么只添加url参数数据
				var urlOptions = Cesium.queryToObject(window.location.search.substring(1));
				const tilesetUrl = urlOptions.tilesetUrl;
				const tilesetTitle = urlOptions.tilesetTitle || '未命名三维瓦片';

				XE.MVVM.watch(() => ({
					labserver: earthUI.labServer.server,
					sceneID: earthUI.labScene.sceneID,
				}), params => {
					let searchObj = {};
					if (params.sceneID) {
						searchObj.scene = params.sceneID;
					}
					if (params.labserver && params.labserver !== '//localhost:9000/') {
						searchObj.labserver = params.labserver;
					}

					const searchStr = Cesium.objectToQuery(searchObj);

					(searchStr.length > 0) && window.history.replaceState(null, null, '?' + searchStr);
				});

				if (urlOptions.labserver) {
					if (!urlOptions.labserver.endsWith('/')) {
						urlOptions.labserver += '/';
					}
					earthUI.labServer.server = urlOptions.labserver;
				}

				//获取url参数，如果有场景地址，那么先获取场景信息 
				if (urlOptions.scene) {
					earthUI.labScene.loadScene(urlOptions.scene);
				} else if (tilesetUrl) {
					initEarthWithTilesetUrl(earthUI.earth, tilesetUrl, tilesetTitle);
				}
				//否则按照示例代码方法创建
				else {
					earthUI.earth.sceneTree.root = {
						"children": [{
							"title": "新建场景",
							"children": [{
								"czmObject": {
									"name": "谷歌影像",
									"xbsjType": "Imagery",
									"xbsjImageryProvider": {
										"XbsjImageryProvider": {
											"url": "http://mt3.google.cn/vt/lyrs=y@258000000&hl=zh-CN&gl=CN&src=app&x={x}&y={y}&z={z}&s=Ga",
											"srcCoordType": "GCJ02",
											"dstCoordType": "WGS84",
										},
									}
								}
							}]
						}, ]
					}
				}

				if (urlOptions.lang) {
					earthUI.language = (urlOptions.lang == 'en-US' ? 'en' : 'zh');
				}


				// //显示自定义对象的，自定义属性窗口
				// var obj1 = {
				//     name: 'obj1'
				// };
				// earthUI.showPropertyWindow(obj1, {
				//     component: myTool
				// });

				/*
				//注意myTool只是个模板，还不是vue组件，对于两个不同的对象 我们使用同一个模板myTool 会创建两个 vue组件实例
				var obj2 = {
				    name: 'obj2'
				}
				earthUI.showPropertyWindow(obj2, {
				    component: myTool
				});
				*/
			});
		}
	}
</script>

<style>
</style>
